package com.example.demo.method.patter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 将华氏温度转换为摄氏温度
 */
public class FtocTemplatetMethod extends Application {

    private InputStreamReader isr;
    private BufferedReader br;

    public static void main(String[] args) {
        (new FtocTemplatetMethod()).run();
    }
    @Override
    protected void init() {
        isr = new InputStreamReader(System.in);
        br = new BufferedReader(isr);
    }

    @Override
    protected void idle() {
        String fahrString = readLineAndReturnNullIfError();
        if (fahrString == null || fahrString.length() == 0){
            setDone();
        } else {
            double fahr = Double.parseDouble(fahrString);
            double ceclcius = 5.0 / 9.0 * (fahr - 32);
            System.out.println("F = "+fahr+" , C = "+ceclcius);
        }
    }

    @Override
    protected void cleanup() {
        System.out.println("ftoc exit");
    }

    private String readLineAndReturnNullIfError(){
        String s;
        try{
            s = br.readLine();
        }catch (IOException e){
            s = null;
        }
        return s;
    }















}
